/*
 * UploadCast.fx
 *
 * Created on 19 nov. 2009, 23:29:47
 */

package javafx_20092010_reeks2.espoirgahungere;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import java.lang.String;
import java.io.File;


/**
 * @author esp
 */

public class UploadCast {

   var fileChooser:JFileChooser;

    public function createCastBrowser(){
       fileChooser = new JFileChooser();
       var filter:ScreenCastFileFilter =  new UploadCast.ScreenCastFileFilter();
       fileChooser.setFileFilter(filter);

   }

   
    public function browseUpload() : File {

       if(fileChooser == null )
                return null;
                
       var file:File = null;
       var ret:Integer = fileChooser.showDialog(null, "Upload A cast ");

       if(ret == JFileChooser.APPROVE_OPTION){
           file= fileChooser.getSelectedFile();
       }

       return file;
   }
}

class ScreenCastFileFilter extends FileFilter {

    var extSwf:String = "swf";


    override public function getDescription () : String {
      return "Allen maar flash bestanden : swf";
    }

    override public function accept (zeFile : File) : Boolean {

       if(zeFile.isDirectory())
            return true;

       if(extension(zeFile).equals(extSwf))
            return true;

        return false;
    }

    function extension(f:File):String{
        var ext:String = null;
        var s:String = f.getName();
        var i:Number = s.lastIndexOf('.');

        if ( (i > 0)  and  (i < s.length() - 1) ) {
            ext = s.substring(i+1).toLowerCase();
        }
        return ext;
    }


}




 


